package fenzhixianjie.onClass.exer04;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

class Read {
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");

    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(nextLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException {
        return bf.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        Read read = new Read();
        int initState = 0;
        // b => 0  w => 1
        for (int i = 0; i < 4; i++) {
            String line = read.next();
            for (int j = 0; j < 4; j++) {
                int powValue = i * 4 + j;
                char value = line.charAt(j);
                if (value == 'w') {
                    initState += Math.pow(2, powValue);
                }
            }
        }
        Queue<Integer> queue = new LinkedList<>();
        Set<Integer> set = new HashSet<>();
        queue.offer(initState);
        set.add(initState);
        int step = 0;
        while (!queue.isEmpty()) {
            int size = queue.size();
            while (size > 0) {
                int top = queue.poll();
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        int nextState = 0;
                        for (int k = 0; k < 4; k++) {
                            for (int l = 0; l < 4; l++) {
                                int bit = (top >> (4 * k + l)) & 1;
                                int dist = Math.abs(i - k) + Math.abs(j - l);
                                if (dist <= 1 && bit == 0) {
                                    nextState += Math.pow(2, 4 * k + l);
                                } else if (dist > 1 && bit == 1) {
                                    nextState += Math.pow(2, 4 * k + l);
                                }
                            }
                        }
                        if (nextState == 0 || nextState == Short.MAX_VALUE) {
                            System.out.println(step + 1);
                            return;
                        }
                        if (!set.contains(nextState)) {
                            set.add(nextState);
                            queue.offer(nextState);
                        }
                    }
                }
                size--;
            }
            step++;
        }
        System.out.println("Impossible");
    }
}